//
//  SelectFileListVC.m
//  ChangChat
//
//  Created by Cocoa on 2019/9/30.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "SelectFileListVC.h"
#import "CacheHelper.h"
#import "FileCell.h"

@interface SelectFileListVC ()

@end

@implementation SelectFileListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.navigationItem.title = @"选择文件";
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.k_title(@"取消").k_titleColor(UIColor.whiteColor);
    [btn addTarget:self action:@selector(handleBackItemAction) forControlEvents:UIControlEventTouchUpInside];
    self.dataSource = [[Cache_Help allFileName] mutableCopy];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
- (void)setupUI {
    [self.tableView registerClass:NSClassFromString(@"FileCell") forCellReuseIdentifier:@"FileCell"];
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FileCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FileCell" forIndexPath:indexPath];
    
    cell.fileNameLabel.text = self.dataSource[indexPath.row];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.didSelectFileBlock) {
        self.didSelectFileBlock(self.dataSource[indexPath.row]);
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
